
import { reqGoodsInfo,reqAddOrUpdateShopCart } from "@/api"
import { getUUID } from "@/utils/uuid_token";

export default{
    state:{
       goodInfo:{},
       uuid_token:getUUID()
    },
    mutations:{
        GETGOODINFO(state,goodInfo){
            state.goodInfo=goodInfo
        }
    },  
    actions:{
        async getGoodInfo({commit},skuId){let res=await reqGoodsInfo(skuId);
        if(res.code==200){
            commit('GETGOODINFO',res.data)
        }
        },
        async addOrUpdateShopCart({commit},{skuId,skuNum}){
            let res=await 
            reqAddOrUpdateShopCart(skuId,skuNum);
            console.log(commit,res)
            if(res.code==200){
                return "ok"
            }else{
                return Promise.reject(new Error('file'))
            }
        }
    },
    getters:{
        categoryView(state){
            return state.goodInfo.categoryView||{}
        },
        skuInfo(state){
            return state.goodInfo.skuInfo
        },
        spuSaleAttrList(state){
            return state.goodInfo.spuSaleAttrList||[]
        }
    }
}